package cn.cl;

import java.io.*;
import java.net.*;

public class SocketTest{
    public static void main(String[] args) throws Exception{
        ServerSocket server = new ServerSocket(8090);
        System.out.println("step1: new ServerSocket(8090)");
        while(true){
            Socket client = server.accept();
            System.out.println("step2:client\t"+client.getPort());
            new Thread(new Runnable(){
                Socket ss;
                public Runnable setSocket(Socket s){
                    ss = s;
                    return this;
                }
                public void run(){
                    try{
                        InputStream in = ss.getInputStream();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                        while(true){
                            System.out.println(reader.readLine());
                        }
                    }catch(Exception e){
                        e.printStackTrace();
                    }
                }
            }.setSocket(client)).start();
        }

    }
}